/*
 * ! Ext JS Library 3.2.0 Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com http://www.extjs.com/license
 */
/**
 * @class Ext.ux.grid.filter.NumericFilter
 * @extends Ext.ux.grid.filter.Filter Filters using an Ext.ux.menu.RangeMenu.
 *          <p>
 *          <b><u>Example Usage:</u></b>
 *          </p>
 * 
 * <pre><code>
 *     
 *  var filters = new Ext.ux.grid.GridFilters({
 *  ...
 *  filters: [{
 *  type: 'numeric',
 *  dataIndex: 'price'
 *  }]
 *  });
 * </code></pre>
 */
Ext.ux.grid.filter.NumericListFilter = Ext.extend(
		Ext.ux.grid.filter.NumericFilter, {

			separate : ';',
			/**
			 * @private Template method that is to get and return serialized
			 *          filter data for transmission to the server.
			 * @return {Object/Array} An object or collection of objects
			 *         containing key value pairs representing the current
			 *         configuration of the filter.
			 */
			getSerialArgs : function() {
				var key, args = [], values = this.menu.getValue();
				for (key in values) {
					args.push({
								type : 'numericList',
								comparison : key,
								value : values[key]
							});
				}
				return args;
			},

			/**
			 * Template method that is to validate the provided Ext.data.Record
			 * against the filters configuration.
			 * 
			 * @param {Ext.data.Record}
			 *            record The record to validate
			 * @return {Boolean} true if the record is valid within the bounds
			 *         of the filter, false otherwise.
			 */
			validateRecord : function(record) {
				var val = record.get(this.dataIndex);
				var vals = null;
				if (!Ext.isEmpty(val)) {
					vals = val.split(this.separate);
				}
				var length = vals.length;
				values = this.getValue();
				var flageq = false, flaglt = false, flaggt = false;
				if (values.eq !== undefined) {
					for (var i = 0; i < length; i++) {
						if (values.eq == vals[i]) {
							return true;
						}
					}
				}
				if (values.lt !== undefined) {
					for (var i = 0; i < length; i++) {
						if (values.lt >= vals[i]) {
							flaglt = true;
							break;
						}
					}
				}
				if (values.gt !== undefined) {
					for (var i = 0; i < length; i++) {
						if (values.gt <= vals[i]) {
							flaggt = true;
						}
					}
				}
				if (values.lt !== undefined && values.gt !== undefined) {
					return flaglt && flaggt;
				} else {
					return  flaglt || flaggt;
				}

			}
		});